
var u = navigator.userAgent;
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端


export {isiOS,isAndroid}

/**
 * 调用移动端方法
 * @param name
 * @param params
 */
export const appFunc = (name = '',params = {})=>{
    window.webkit.messageHandlers[name].postMessage(params);
};

/**
 *  返回上一页
 */
export const goBack = ()=>{
    appFunc('goBack');
};

/**
 * 判断是否是苹果齐刘海
 * @param callback
 */
export const isIphoneX = (callback)=>{
    try {
        appFunc('iphoneX');
        window.iosPushBangScreen = data =>{
            callback(data);
        };
    }catch (e) {
        callback(3)
    }

};

/**
 * 获取苹果手机token
 * @param callback
 */
export const getToken = (callback)=>{
    try {
        appFunc('getToken');
        window.iosPushToken = data => {
            callback(data)
        }
    }catch (err) {
        console.log(err)
    }
};
